<?php

namespace app\enterprise\controller;


use app\adminapi\controller\AuthController;
use think\facade\Request;
use app\enterprise\service\UploadService;
use think\facade\Filesystem;

class Upload extends AuthController
{
    public function upload()
    {
        // 获取上传的文件
        $file = Request::file('file');

        if (!$file) {
            return app('json')->fail('未上传文件');
        }
        try {
            // 使用上传服务处理上传逻辑
            $result = UploadService::upload($file);
            $url = Filesystem::disk('public')->url($result['url']);


            return app('json')->success([
                'url' => request()->domain().$url,
                'name' => $result['name'],
                'type' => $result['type']
            ]);
        } catch (\Exception $e) {
            return app('json')->fail($e->getMessage());
        }


    }

}